/**
 * Created with Intellij IDEA.
 * Description:
 * User: 28318
 * Date: 2025-11-06
 * Time: 19:44
 */

class MyLinkList{

    public MyList head;

    class MyList {
        public int val;
        public MyList next;

        public MyList() {
        }

        public MyList(int data) {
            this.val = data;
        }
    }

    public MyLinkList() {
        head = new MyList();
    }

    public MyLinkList(int data) {
        head = new MyList(data);
    }

    public boolean chkPalindrome(){
        MyList fast = this.head;
        MyList slow = this.head;
        if (this.head == null){
            return false;
        }
        while (fast != null && fast.next != null){
            fast = fast.next.next;
            slow = slow.next;
        }
        MyList cur = slow.next;
        while (cur != null){
            MyList curN = cur.next;
            cur.next = slow;
            slow = cur;
            cur = curN;
        }
        MyList newH = this.head;
        while (newH != slow){
            if (newH.val != slow.val){
                return false;
            }
            if (newH.next == slow){
                return true;
            }
            newH = newH.next;
            slow = slow.next;
        }
        return true;
    }
}

public class Test {

    public static void main(String[] args) {
        MySingleLinkedList nums = new MySingleLinkedList();
        nums.addLast(1);
//        nums.addLast(3);
//        nums.addLast(5);
//        nums.addLast(7);
//        nums.addLast(9);
        nums.display();
        MySingleLinkedList nums2 = new MySingleLinkedList();
        nums2.addLast(2);
        nums2.addLast(4);
        nums2.addLast(6);
        nums2.addLast(8);
        nums2.addLast(10);
        nums2.display();
//        nums.clear();
//        nums.removeAllKey(1);
        nums.head = nums.mergeTwoLists(nums.head, nums2.head);
        nums.display();
    }

    public static void main2(String[] args) {
        MySingleLinkedList nums = new MySingleLinkedList();
        nums.addLast(1);
        nums.addLast(1);
        nums.addLast(2);
        nums.addLast(1);
//        nums.addLast(2);
//        nums.addLast(1);
        nums.display();
//        nums.head = nums.partition(nums.head, 3);
        System.out.println(nums.isPalindrome(nums.head));
    }

    public static void main1(String[] args) {
        MyDoubleLinkedList nums = new MyDoubleLinkedList();
        nums.addLast(1);
        nums.addFirst(2);
        nums.addLast(3);
        nums.addFirst(4);
        nums.addLast(5);
        nums.display();
        nums.addIndex(5,6);
        nums.addIndex(0,6);
        nums.addIndex(3,6);
        nums.display();
        nums.removeAllKey(6);
//        nums.remove(5);
        nums.display();
        nums.clear();
        nums.display();
    }

    public static void main0(String[] args) {

        MySingleLinkedList nums = new MySingleLinkedList();
        nums.addLast(1);
        nums.addLast(2);
        nums.addLast(3);
        nums.addLast(4);
        nums.addLast(5);
        nums.display();
//        nums.head = nums.removeElements(nums.head,3);
//        nums.clear();
//        nums.head = nums.reverseList(nums.head);
//        System.out.println(nums.kthToLast(nums.head, 5));
        nums.display();
        nums.addFirst(6);
        nums.addIndex(4, 6);
        nums.addLast(6);
        nums.display();
        nums.remove(6);
        nums.display();
        nums.removeAllKey(6);
        nums.display();
    }

}
